<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .bg{
            background-color: red;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div class="bg" id="bg"></div>
</body>
<script>
    //获取id值是特定值网页元素在js中的表示方式
    var bg = document.getElementById("bg");
    bg.onclick=function(){
        alert("div被点击了");
    }
    //当鼠标移动到div上时，在控制台打印输出
    bg.onmouseover=function(){
        console.log("鼠标箭头移上了div");
    }
    bg.onmouseout=function(){
        console.log("鼠标箭头从div上移开了");
    }
</script>
</html>